//
//  TranManager_NavBar.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TranManager_NavBar.h"

@interface TranManager_NavBar ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIView *bgView;
//@property (nonatomic, strong) TranNavMenuView *heTongView;
//@property (nonatomic, strong) TranNavMenuView *siJiView;
//@property (nonatomic, strong) TranNavMenuView *cheLiangView;

@property (nonatomic, strong) TranNavMenuView *taskView;
@property (nonatomic, strong) TranNavMenuView *cheLiangView;
@property (nonatomic, strong) TranNavMenuView *siJiView;
@property (nonatomic, strong) TranNavMenuView *heTongView;

@end

@implementation TranManager_NavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

-(void)setIsDanRen:(BOOL)isDanRen {
    _isDanRen = isDanRen;
    [self configUI];
}

- (void)configUI {
    self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, StatusBarHeight + 30, ScreenW - 40, 25)];
    self.titleLab.textColor = HexColor(0xffffff);
    self.titleLab.font = BoldFontOfSize(24);
    self.titleLab.text = @"运输管理";
    [self addSubview:self.titleLab];
    
    if (self.isDanRen) {
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(20, self.titleLab.nim_bottom + 20, ScreenW - 40, 100)];
        CGFloat viewW = self.bgView.nim_width * 0.33333;
        CGFloat viewH = 70;
        self.taskView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(0, 15, viewW, viewH)];
        self.cheLiangView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.taskView.nim_right, 15, viewW, viewH)];
        self.heTongView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.cheLiangView.nim_right, 15, viewW, viewH)];
        self.siJiView = [[TranNavMenuView alloc] initWithFrame:CGRectZero];
    }else {
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(20, self.titleLab.nim_bottom + 20, ScreenW - 40, 247)];
        CGFloat viewW = self.bgView.nim_width * 0.5;
        CGFloat viewH = 70;
        CGFloat margin = (self.bgView.nim_height - 2 * viewH) * 0.33333;
        self.taskView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(0, margin, viewW, viewH)];
        self.cheLiangView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.taskView.nim_right, margin, viewW, viewH)];
        self.siJiView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(0, self.taskView.nim_bottom + margin, viewW, viewH)];
        self.heTongView = [[TranNavMenuView alloc] initWithFrame:CGRectMake(self.siJiView.nim_right, self.siJiView.nim_top, viewW, viewH)];
    }
    
    self.taskView.iconUrl = @"iocn_main_task";
    self.taskView.titleStr = @"我的任务";
    __weak_self;
    self.taskView.clickBlock = ^{
        if (weakself.taskBlock) {
            weakself.taskBlock();
        }
    };
    [self.bgView addSubview:self.taskView];
    
    
    self.heTongView.iconUrl = @"iocn_main_contract";
    self.heTongView.titleStr = @"合同管理";
    
    self.heTongView.clickBlock = ^{
        if (weakself.heTongBlock) {
            weakself.heTongBlock();
        }
    };
    [self.bgView addSubview:self.heTongView];
    
    
    self.siJiView.iconUrl = @"icon_main_driver";
    self.siJiView.titleStr = @"司机管理";
    self.siJiView.clickBlock = ^{
        if (weakself.siJiBlock) {
            weakself.siJiBlock();
        }
    };
    [self.bgView addSubview:self.siJiView];
    
    
    self.cheLiangView.iconUrl = @"icon_main_vehicle";
    self.cheLiangView.titleStr = @"车辆管理";
    self.cheLiangView.clickBlock = ^{
        if (weakself.cheLiangBlock) {
            weakself.cheLiangBlock();
        }
    };
    [self.bgView addSubview:self.cheLiangView];
    
    self.bgView.backgroundColor = HexColor(0xffffff);
    self.bgView.layer.cornerRadius = 4;
    //设置阴影颜色
    self.bgView.layer.shadowColor = HexColorA(0x2B2C44, 0.1).CGColor;
    //设置阴影的透明度
    self.bgView.layer.shadowOpacity = 1.f;
    //设置阴影的偏移
    self.bgView.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
    //设置阴影半径
    self.bgView.layer.shadowRadius = 5.0f;
    [self addSubview:self.bgView];
    
    self.height = self.bgView.nim_bottom + 20;
}

@end

@interface TranNavMenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation TranNavMenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        if (frame.size.width && frame.size.height) {
            self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 6, 40, 40)];
            [self addSubview:self.iconImgView];
            
            self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 9, frame.size.width, 15)];
            self.titleLab.textColor = HexColor(0x585974);
            self.titleLab.font = [UIFont systemFontOfSize:14];
            self.titleLab.textAlignment = NSTextAlignmentCenter;
            [self addSubview:self.titleLab];
            
            self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
            [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.clickBtn];
        }
        
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

@end
